import { util } from '@/utils'
import { useState } from 'react'

function useDarkMode() {
  const html = document.documentElement
  const [isDarkMode, setIsDarkMode] = useState(html.className.includes('dark'))
  function toggle() {
    setIsDarkMode(!isDarkMode)
    html.classList.remove('dark', 'light')
    html.classList.toggle(isDarkMode ? 'light' : 'dark')
    util.Theme.setTheme(isDarkMode ? 'light' : 'dark')
  }
  return {
    isDarkMode,
    toggle,
  }
}

export default useDarkMode
